


use "__________________\VOTER_Survey_Jan217_Release1-dta.dta", clear



*FEELING THERMOMETERS FOR PANEL ANALYSIS 1 AND 2

*black ft
gen ftblack2016=ft_black_2016
replace ftblack2016=. if ft_black_2016>=997
gen ftblack2017=ft_black_2017
replace ftblack2017=. if ft_black_2017>=997
gen ftblack2012=blacks_t_baseline
replace ftblack2012=. if blacks_t_baseline>=997

*gen zscore black ft
sort ftblack2012
egen ftblack2012mean=mean(ftblack2012)
egen ftblack2012sd=sd(ftblack2012)
gen zftblack2012=(ftblack2012-ftblack2012mean)/ftblack2012sd

sort ftblack2017
egen ftblack2017mean=mean(ftblack2017)
egen ftblack2017sd=sd(ftblack2017)
gen zftblack2017=(ftblack2017-ftblack2017mean)/ftblack2017sd

*change in zscore of black ft
gen zftblack1712=zftblack2017-zftblack2012


*hispanic ft
gen fthisp2016=ft_hisp_2016
replace fthisp2016=. if ft_hisp_2016>=997
gen fthisp2017=ft_hisp_2017
replace fthisp2017=. if ft_hisp_2017>=997
gen fthisp2012=latinos_t_baseline
replace fthisp2012=. if latinos_t_baseline>=997


*zscore of hisp ft
sort fthisp2012
egen fthisp2012mean=mean(fthisp2012)
egen fthisp2012sd=sd(fthisp2012)
gen zfthisp2012=(fthisp2012-fthisp2012mean)/fthisp2012sd

sort fthisp2017
egen fthisp2017mean=mean(fthisp2017)
egen fthisp2017sd=sd(fthisp2017)
gen zfthisp2017=(fthisp2017-fthisp2017mean)/fthisp2017sd

*change in zscore of hisp ft
gen zfthisp1712=zfthisp2017-zfthisp2012


*asian ft
gen ftasian2016=ft_asian_2016
replace ftasian2016=. if ft_asian_2016>=997
gen ftasian2017=ft_asian_2017
replace ftasian2017=. if ft_asian_2017>=997
gen ftasian2012=asians_t_baseline
replace ftasian2012=. if asians_t_baseline>=997

*zscore of asian ft

sort ftasian2012
egen ftasian2012mean=mean(ftasian2012)
egen ftasian2012sd=sd(ftasian2012)
gen zftasian2012=(ftasian2012-ftasian2012mean)/ftasian2012sd

sort ftasian2017
egen ftasian2017mean=mean(ftasian2017)
egen ftasian2017sd=sd(ftasian2017)
gen zftasian2017=(ftasian2017-ftasian2017mean)/ftasian2017sd

*change in zscore of asian ft

gen zftasian1712=zftasian2017-zftasian2012


*christian ft, reverse coded
gen ftchrist2016=100-ft_christ_2016
replace ftchrist2016=. if ft_christ_2016>=997
gen ftchrist2017=100-ft_christ_2017
replace ftchrist2017=. if ft_christ_2017>=997
gen ftchrist2012=100-christians_t_baseline
replace ftchrist2012=. if christians_t_baseline>=997


sort ftchrist2012
egen ftchrist2012mean=mean(ftchrist2012)
egen ftchrist2012sd=sd(ftchrist2012)
gen zftchrist2012=(ftchrist2012mean-ftchrist2012)/ftchrist2012sd

sort ftchrist2017
egen ftchrist2017mean=mean(ftchrist2017)
egen ftchrist2017sd=sd(ftchrist2017)
gen zftchrist2017=(ftchrist2017mean-ftchrist2017)/ftchrist2017sd

*change in zscore of christian ft
gen zftchrist1712=zftchrist2017-zftchrist2012


*muslim ft

gen ftmuslim2012=muslims_t_baseline
replace ftmuslim2012=. if muslims_t_baseline>=997
gen ftmuslim2016=ft_muslim_2016
replace ftmuslim2016=. if ft_muslim_2016>=997
gen ftmuslim2017=ft_muslim_2017
replace ftmuslim2017=. if ft_muslim_2017>=997

*zscore of muslim ft

sort ftmuslim2012
egen ftmuslim2012mean=mean(ftmuslim2012)
egen ftmuslim2012sd=sd(ftmuslim2012)
gen zftmuslim2012=(ftmuslim2012-ftmuslim2012mean)/ftmuslim2012sd

sort ftmuslim2017
egen ftmuslim2017mean=mean(ftmuslim2017)
egen ftmuslim2017sd=sd(ftmuslim2017)
gen zftmuslim2017=(ftmuslim2017-ftmuslim2017mean)/ftmuslim2017sd

*change in zscore of muslim ft
gen zftmuslim1712=zftmuslim2017-zftmuslim2012


*jewish ft
gen ftjew2016=ft_jew_2016
replace ftjew2016=. if ft_jew_2016>=997
gen ftjew2017=ft_jew_2017
replace ftjew2017=. if ft_jew_2017>=997
gen ftjew2012=jews_t_baseline
replace ftjew2012=. if jews_t_baseline>=997

*zscore of jewish ft

sort ftjew2012
egen ftjew2012mean=mean(ftjew2012)
egen ftjew2012sd=sd(ftjew2012)
gen zftjew2012=(ftjew2012-ftjew2012mean)/ftjew2012sd


sort ftjew2017
egen ftjew2017mean=mean(ftjew2017)
egen ftjew2017sd=sd(ftjew2017)
gen zftjew2017=(ftjew2017-ftjew2017mean)/ftjew2017sd

*change in zscore of jewish ft
gen zftjew1712=zftjew2017-zftjew2012



*gay ft
gen ftgay2016=ft_gays_2016
replace ftgay2016=. if ft_gays_2016>=997
gen ftgay2017=ft_gays_2017
replace ftgay2017=. if ft_gays_2017>=997
gen ftgay2012=gays_t_baseline
replace ftgay2012=. if gays_t_baseline>=997


*zscore of gay ft

sort ftgay2017
egen ftgay2017mean=mean(ftgay2017)
egen ftgay2017sd=sd(ftgay2017)
gen zftgay2017=(ftgay2017-ftgay2017mean)/ftgay2017sd

sort ftgay2016
egen ftgay2016mean=mean(ftgay2016)
egen ftgay2016sd=sd(ftgay2016)
gen zftgay2016=(ftgay2016-ftgay2016mean)/ftgay2016sd

sort ftgay2012
egen ftgay2012mean=mean(ftgay2012)
egen ftgay2012sd=sd(ftgay2012)
gen zftgay2012=(ftgay2012-ftgay2012mean)/ftgay2012sd

*change in zscore of gay ft

gen zftgay1712=zftgay2017-zftgay2012



*ATTITUDE MEASURES FOR PANEL ANALYSIS 3 and 4

*RACIAL ATTITUDES from racial resentment battery
*conservative position coded as 1, liberal as 0, .5=don't know

gen racedeserve2016=0
replace racedeserve2016=.25 if race_deservemore_2016==2
replace racedeserve2016=.5 if race_deservemore_2016==8
replace racedeserve2016=.75 if race_deservemore_2016==3
replace racedeserve2016=1 if race_deservemore_2016==4
replace racedeserve2016=. if race_deservemore_2016==.

gen racedeservebase=0
replace racedeservebase=.25 if race_deservemore_baseline==2
replace racedeservebase=.5 if race_deservemore_baseline==3
replace racedeservebase=.75 if race_deservemore_baseline==4
replace racedeservebase=1 if race_deservemore_baseline==5
replace racedeservebase=. if race_deservemore_baseline==.

gen raceovercome2016=0
replace raceovercome2016=.25 if race_overcome_2016==3
replace raceovercome2016=.5 if race_overcome_2016==8
replace raceovercome2016=.75 if race_overcome_2016==2
replace raceovercome2016=1 if race_overcome_2016==1
replace raceovercome2016=. if race_overcome_2016==.

gen raceovercomebase=0
replace raceovercomebase=.25 if race_overcome_baseline==4
replace raceovercomebase=.5 if race_overcome_baseline==3
replace raceovercomebase=.75 if race_overcome_baseline==2
replace raceovercomebase=1 if race_overcome_baseline==1
replace raceovercomebase=. if race_overcome_baseline==.

gen racetry2016=0
replace racetry2016=.25 if race_tryharder_2016==3
replace racetry2016=.5 if race_tryharder_2016==8
replace racetry2016=.75 if race_tryharder_2016==2
replace racetry2016=1 if race_tryharder_2016==1
replace racetry2016=. if race_tryharder_2016==.

gen racetrybase=0
replace racetrybase=.25 if race_tryharder_baseline==4
replace racetrybase=.5 if race_tryharder_baseline==3
replace racetrybase=.75 if race_tryharder_baseline==2
replace racetrybase=1 if race_tryharder_baseline==1
replace racetrybase=. if race_tryharder_baseline==.

gen raceslave2016=0
replace raceslave2016=.25 if race_slave_2016==2
replace raceslave2016=.5 if race_slave_2016==8
replace raceslave2016=.75 if race_slave_2016==3
replace raceslave2016=1 if race_slave_2016==4
replace raceslave2016=. if race_slave_2016==.

gen raceslavebase=0
replace raceslavebase=.25 if race_slave_baseline==2
replace raceslavebase=.5 if race_slave_baseline==3
replace raceslavebase=.75 if race_slave_baseline==4
replace raceslavebase=1 if race_slave_baseline==5
replace raceslavebase=. if race_slave_baseline==.

*composite racial attitudes score by year, and change

gen raceatt2016=(racedeserve2016+raceovercome2016+racetry2016+raceslave2016)/4
gen raceatt2012=(racedeservebase+raceovercomebase+racetrybase+raceslavebase)/4
gen changeraceatt1612=raceatt2012-raceatt2016



*IMMIGRATION

*0 equals liberal position; 1 equals conservative position; .5 =no change or not sure

*illegal immigrants drain or make contribution
gen immicont2016=.
replace immicont2016=1 if immi_contribution_2016==3
replace immicont2016=.5 if immi_contribution_2016==8
replace immicont2016=.5 if immi_contribution_2016==2
replace immicont2016=0 if immi_contribution_2016==1

gen immicont2012=.
replace immicont2012=1 if immi_contribution_baseline==3
replace immicont2012=.5 if immi_contribution_baseline==8
replace immicont2012=.5 if immi_contribution_baseline==2
replace immicont2012=0 if immi_contribution_baseline==1

*illegal immigrants pathway to citizenship, favor or oppose
gen daca2016=.
replace daca2016=1 if immi_naturalize_2016==2
replace daca2016=.5 if immi_naturalize_2016==8
replace daca2016=0 if immi_naturalize_2016==1

gen daca2012=.
replace daca2012=1 if immi_naturalize_baseline==2
replace daca2012=.5 if immi_naturalize_baseline==3
replace daca2012=0 if immi_naturalize_baseline==1

*easier or harder for foreigners to immigrate legally
gen immigharder2016=.
replace immigharder2016=1 if immi_makedifficult_2016==5
replace immigharder2016=.75 if immi_makedifficult_2016==4
replace immigharder2016=.5 if immi_makedifficult_2016==8
replace immigharder2016=.5 if immi_makedifficult_2016==3
replace immigharder2016=.25 if immi_makedifficult_2016==2
replace immigharder2016=0 if immi_makedifficult_2016==1

gen immigharder2012=.
replace immigharder2012=1 if immi_makedifficult_baseline==5
replace immigharder2012=.75 if immi_makedifficult_baseline==4
replace immigharder2012=.5 if immi_makedifficult_baseline==8
replace immigharder2012=.5 if immi_makedifficult_baseline==3
replace immigharder2012=.25 if immi_makedifficult_baseline==2
replace immigharder2012=0 if immi_makedifficult_baseline==1


*composite scores on immigration by year

gen immigration2012=(immicont2012+daca2012+immigharder2012)/3
gen immigration2016=(immicont2016+daca2016+immigharder2016)/3


*change over time; positive value of change means: liberal direction
gen changeimmigration1612=immigration2012-immigration2016


*RELIGION

*church attendance
gen chatt2016=0
replace chatt2016=.2 if pew_churatd_2016==5
replace chatt2016=.4 if pew_churatd_2016==4
replace chatt2016=.6 if pew_churatd_2016==3
replace chatt2016=.8 if pew_churatd_2016==2
replace chatt2016=1 if pew_churatd_2016==1
replace chatt2016=. if pew_churatd_2016==7
replace chatt2016=. if pew_churatd_2016==.
gen chatt2017=0
replace chatt2017=.2 if pew_churatd_2017==5
replace chatt2017=.4 if pew_churatd_2017==4
replace chatt2017=.6 if pew_churatd_2017==3
replace chatt2017=.8 if pew_churatd_2017==2
replace chatt2017=1 if pew_churatd_2017==1
replace chatt2017=. if pew_churatd_2017==7
replace chatt2017=. if pew_churatd_2017==.
gen chatt2012=0
replace chatt2012=.2 if pew_churatd_baseline==5
replace chatt2012=.4 if pew_churatd_baseline==4
replace chatt2012=.6 if pew_churatd_baseline==3
replace chatt2012=.8 if pew_churatd_baseline==2
replace chatt2012=1 if pew_churatd_baseline==1
replace chatt2012=. if pew_churatd_baseline==7
replace chatt2012=. if pew_churatd_baseline==.


*ABORTION ATTITUDES
*0 = legal in all cases; 1 = illegal in all cases; .5 mixed
gen abort2016=.
replace abort2016=1 if abortview3_2016==3
replace abort2016=.5 if abortview3_2016==2
replace abort2016=0 if abortview3_2016==1
gen abort2012=.
replace abort2012=1 if abortview3_baseline==3
replace abort2012=.5 if abortview3_baseline==2
replace abort2012=0 if abortview3_baseline==1

*change in abortion attitudes; a positive value for this equals mvmt in liberal direction
gen changeabort1612=abort2012-abort2016




*CLASS REDISTRIBUTION ATTITUDES

*attitudes on taxing wealthy
*1 equals don't favor tax; 0 equals favor tax; not sure coded as middle, .5


gen taxwealth2016=.
replace taxwealth2016=1 if taxdoug_2016==2
replace taxwealth2016=.5 if taxdoug_2016==3
replace taxwealth2016=0 if taxdoug_2016==1

gen taxwealth2012=.
replace taxwealth2012=1 if taxwealth_baseline==2
replace taxwealth2012=.5 if taxwealth_baseline==3
replace taxwealth2012=0 if taxwealth_baseline==1



*attitudes on business regulation; 1= too much; 0=too little; .5 =not sure
gen bizreg2016=.
replace bizreg2016=1 if govt_reg_2016==1
replace bizreg2016=.5 if govt_reg_2016==2
replace bizreg2016=.5 if govt_reg_2016==8
replace bizreg2016=0 if govt_reg_2016==3

gen bizreg2012=.
replace bizreg2012=1 if govt_reg_baseline==1
replace bizreg2012=.5 if govt_reg_baseline==2
replace bizreg2012=.5 if govt_reg_baseline==8
replace bizreg2012=0 if govt_reg_baseline==3

*composite measure on taxing and regulation
gen taxbizreg2016=(taxwealth2016+bizreg2016)/2
gen taxbizreg2012=(taxwealth2012+bizreg2012)/2

*change in taxbizreg
gen changetaxbizreg1612=taxbizreg2012-taxbizreg2016



*PARTY AND IDEOLOGY

gen pidthree2016=0
replace pidthree2016=-1 if pid3_2016==1
replace pidthree2016=1 if pid3_2016==2
replace pidthree2016=. if pid3_2016==.
replace pidthree2016=. if pid3_2016==5
gen pidthree2017=0
replace pidthree2017=-1 if pid3_2017==1
replace pidthree2017=1 if pid3_2017==2
replace pidthree2017=. if pid3_2017==.
replace pidthree2017=. if pid3_2017==5
gen pidthree2012=0
replace pidthree2012=-1 if pid3_baseline==1
replace pidthree2012=1 if pid3_baseline==2
replace pidthree2012=. if pid3_baseline==.
replace pidthree2012=. if pid3_baseline==5



gen pidseven2016=pid7_2016
replace pidseven2016=. if pid7_2016==8
gen pidseven2017=pid7_2017
replace pidseven2017=. if pid7_2017==8
gen pidseven2012=pid7_baseline
replace pidseven2012=. if pid7_baseline==8

gen dem2016=0
replace dem2016=1 if pid7_2016<4
gen rep2016=0
replace rep2016=1 if pid7_2016>4 & pid7_2016<8

gen dem2017=0
replace dem2017=1 if pid7_2017<4
gen rep2017=0
replace rep2017=1 if pid7_2017>4 & pid7_2017<8

gen dem2012=0
replace dem2012=1 if pid7_baseline<4
replace dem2012=. if pid7_baseline==.
gen rep2012=0
replace rep2012=1 if pid7_baseline>4 & pid7_baseline<8
replace rep2012=. if pid7_baseline==.




*ideology: going from liberal to conservative
gen ideology2016=ideo5_2016
replace ideology2016=. if ideo5_2016==6
gen ideology2017=ideo5_2017
replace ideology2017=. if ideo5_2017==6
gen ideology2012=ideo5_baseline
replace ideology2012=. if ideo5_baseline==6

*ideology dummies

gen liberal2016=.
replace liberal2016=1 if ideo5_2016<3
replace liberal2016=0 if ideo5_2016>2 & ideo5_2016<7
gen liberal2017=.
replace liberal2017=1 if ideo5_2017<3
replace liberal2017=0 if ideo5_2017>2 & ideo5_2017<7
gen liberal2012=.
replace liberal2012=1 if ideo5_baseline<3
replace liberal2012=0 if ideo5_baseline>2 & ideo5_baseline<7


gen conservative2016=.
replace conservative2016=0 if ideo5_2016<4
replace conservative2016=0 if ideo5_2016==6
replace conservative2016=1 if ideo5_2016>2 & ideo5_2016<6
gen conservative2017=.
replace conservative2017=0 if ideo5_2017<4
replace conservative2017=0 if ideo5_2017==6
replace conservative2017=1 if ideo5_2017>2 & ideo5_2017<6
gen conservative2012=.
replace conservative2012=0 if ideo5_baseline<4
replace conservative2012=0 if ideo5_baseline==6
replace conservative2012=1 if ideo5_baseline>2 & ideo5_baseline<6





*DEMOGRAPHIC VARIABLES

*race
gen white2016=0
replace white2016=1 if race_2016==1
gen black2016=0
replace black2016=1 if race_2016==2
gen hisp2016=0
replace hisp2016=1 if race_2016==3
gen asian2016=0
replace asian2016=1 if race_2016==4
gen other2016=0
replace other2016=1 if race_2016>4

gen race2016=race_2016
replace race2016=5 if race_2016>4


gen white2017=0
replace white2017=1 if race_2017==1
gen black2017=0
replace black2017=1 if race_2017==2
gen hisp2017=0
replace hisp2017=1 if race_2017==3
gen asian2017=0
replace asian2017=1 if race_2017==4
gen other2017=0
replace other2017=1 if race_2017>4

gen race2017=race_2017
replace race2017=5 if race_2017>4


gen white2012=0
replace white2012=1 if race_baseline==1
replace white2012=. if race_baseline==.
gen black2012=0
replace black2012=1 if race_baseline==2
replace black2012=. if race_baseline==.
gen hisp2012=0
replace hisp2012=1 if race_baseline==3
replace hisp2012=. if race_baseline==.
gen asian2012=0
replace asian2012=1 if race_baseline==4
replace asian2012=. if race_baseline==.
gen other2012=0
replace other2012=1 if race_baseline>4
replace other2012=. if race_baseline==.

gen race2012=race_baseline
replace race2012=5 if race_baseline>4



*family income, in tens of thousands of dollars; interpolate income as middle of category; in 2012 survey income is top coded at 150,000; every year made comparable to top code in 2012

gen faminc2017=.
replace faminc2017=5000/10000 if faminc_new_2017==1
replace faminc2017=15000/10000 if faminc_new_2017==2
replace faminc2017=25000/10000 if faminc_new_2017==3
replace faminc2017=35000/10000 if faminc_new_2017==4
replace faminc2017=45000/10000 if faminc_new_2017==5
replace faminc2017=55000/10000 if faminc_new_2017==6
replace faminc2017=65000/10000 if faminc_new_2017==7
replace faminc2017=75000/10000 if faminc_new_2017==8
replace faminc2017=90000/10000 if faminc_new_2017==9
replace faminc2017=110000/10000 if faminc_new_2017==10
replace faminc2017=135000/10000 if faminc_new_2017==11
replace faminc2017=175000/10000 if faminc_new_2017>11 & faminc_new_2017<97


gen faminc2016=.
replace faminc2016=5000/10000 if faminc_2016==1
replace faminc2016=15000/10000 if faminc_2016==2
replace faminc2016=25000/10000 if faminc_2016==3
replace faminc2016=35000/10000 if faminc_2016==4
replace faminc2016=45000/10000 if faminc_2016==5
replace faminc2016=55000/10000 if faminc_2016==6
replace faminc2016=65000/10000 if faminc_2016==7
replace faminc2016=75000/10000 if faminc_2016==8
replace faminc2016=90000/10000 if faminc_2016==9
replace faminc2016=110000/10000 if faminc_2016==10
replace faminc2016=135000/10000 if faminc_2016==11
replace faminc2016=175000/10000 if faminc_2016>11 & faminc_2016<97


gen faminc2012=.
replace faminc2012=5000/10000 if faminc_baseline==1
replace faminc2012=15000/10000 if faminc_baseline==2
replace faminc2012=25000/10000 if faminc_baseline==3
replace faminc2012=35000/10000 if faminc_baseline==4
replace faminc2012=45000/10000 if faminc_baseline==5
replace faminc2012=55000/10000 if faminc_baseline==6
replace faminc2012=65000/10000 if faminc_baseline==7
replace faminc2012=75000/10000 if faminc_baseline==8
replace faminc2012=90000/10000 if faminc_baseline==9
replace faminc2012=110000/10000 if faminc_baseline==10
replace faminc2012=135000/10000 if faminc_baseline==11
replace faminc2012=175000/10000 if faminc_baseline>11 & faminc_baseline<97

gen changefaminc1612=faminc2016-faminc2012
gen changefaminc1712=faminc2017-faminc2012




*education; 1 to 6: no hs, hs, some coll, 2 year, 4 year, post grad
gen educ2016=educ_2016
gen educ2012=educ_baseline
gen educ2017=educ_2017
gen educ2019=educ_2019


*age
gen age2016=2016-birthyr_baseline
gen age2012=age2016-4
gen age2017=2017-birthyr_baseline
gen age2019=2019-birthyr_baseline


*male
gen male2012=0
replace male2012 =1 if gender_baseline==1



*OTHER VARIABLES FOR EXPOSURE TO MESSAGING INFRASTRUCTURE and FIXED/FLUID PERSONALITY

*newsint: 1= pays attn politics most of the time
gen newsint2016=0
replace newsint2016=1 if newsint_2016==1
replace newsint2016=.66 if newsint_2016==2
replace newsint2016=.33 if newsint_2016==3
replace newsint2016=. if newsint_2016==.
replace newsint2016=. if newsint_2016==7

gen newsint2017=0
replace newsint2017=1 if newsint_2017==1
replace newsint2017=.66 if newsint_2017==2
replace newsint2017=.33 if newsint_2017==3
replace newsint2017=. if newsint_2017==.
replace newsint2017=. if newsint_2017==7

gen newsint2012=0
replace newsint2012=1 if post_newsint_2012==1
replace newsint2012=.66 if post_newsint_2012==2
replace newsint2012=.33 if post_newsint_2012==3
replace newsint2012=. if post_newsint_2012==.
replace newsint2012=. if post_newsint_2012==7


gen changenewsint1712=newsint2017-newsint2012
gen changenewsint1612=newsint2016-newsint2012

*internet use: only measured in 2012; averaging four measures on hourly use

gen internethome2012=daily_intuse_home_baseline
replace internethome2012=4 if daily_intuse_home_baseline>4
gen internetwork2012=daily_intuse_work_baseline
replace internetwork2012=4 if daily_intuse_work_baseline>4
gen internetmobile2012=daily_intuse_mobile_baseline
replace internetmobile2012=4 if daily_intuse_mobile_baseline>4
gen internetelse2012=daily_intuse_else_baseline
replace internetelse2012=4 if daily_intuse_else_baseline>4

gen internet2012=(16-internethome2012-internetwork2012-internetmobile2012-internetelse2012)/4


*fixed versus fluid; fixed answers coded 1

gen child1=.
replace child1=1 if SOCIAL_CONFORMITY_1_2016==2
replace child1=0 if SOCIAL_CONFORMITY_1_2016==1

gen child2=.
replace child2=1 if SOCIAL_CONFORMITY_2_2016==2
replace child2=0 if SOCIAL_CONFORMITY_2_2016==1

gen child3=.
replace child3=1 if SOCIAL_CONFORMITY_3_2016==1
replace child3=0 if SOCIAL_CONFORMITY_3_2016==2

gen child4=.
replace child4=1 if SOCIAL_CONFORMITY_4_2016==2
replace child4=0 if SOCIAL_CONFORMITY_4_2016==1

gen child=child1+child2+child3+child4
gen fixed2016=0
replace fixed2016=1 if child>2
replace fixed=. if child==.
gen fluid2016=0
replace fluid2016=1 if child<2
replace fluid2016=. if child==.

gen authoritarian=child1+child2+child3+child4
gen authoritarian2016=child1+child2+child3+child4
gen authoritarian2012=child1+child2+child3+child4
gen authoritarian2017=child1+child2+child3+child4


***********************************************************************
*setting weight
*weight_2016: analysis of the December 2016 survey (N=8,000)
*weight_2017: analysis of the July 2017 survey (N=5,000)


*panel analysis on thermometers, 2012 to 2017
*thermometer changes, descriptive stats on changes from 2012 to 2017 (Figure 2a)

svyset [pweight=weight_2017]

svy: mean zftblack1712 if dem2012==1
svy: mean zftblack1712 if rep2012==1
svy: mean zftblack1712 if dem2012==0 & rep2012==0

svy: mean zfthisp1712 if dem2012==1
svy: mean zfthisp1712 if rep2012==1
svy: mean zfthisp1712 if dem2012==0 & rep2012==0

svy: mean zftasian1712 if dem2012==1
svy: mean zftasian1712 if rep2012==1
svy: mean zftasian1712 if dem2012==0 & rep2012==0

svy: mean zftmuslim1712 if dem2012==1
svy: mean zftmuslim1712 if rep2012==1
svy: mean zftmuslim1712 if dem2012==0 & rep2012==0

svy: mean zftgay1712 if dem2012==1
svy: mean zftgay1712 if rep2012==1
svy: mean zftgay1712 if dem2012==0 & rep2012==0

svy: mean zftchrist1712 if dem2012==1
svy: mean zftchrist1712 if rep2012==1
svy: mean zftchrist1712 if dem2012==0 & rep2012==0

svy: mean zftjew1712 if dem2012==1
svy: mean zftjew1712 if rep2012==1
svy: mean zftjew1712 if dem2012==0 & rep2012==0



*sorting on feeling thermometers (Figure 2b)

*2017
gen sortrightf17=0
replace sortrightf17=1 if zfthisp2017<-.5 & zftgay2017<-.5 & zftblack2017<-.5 & zftmuslim2017>=-.5
replace sortrightf17=1 if zfthisp2017<-.5 & zftgay2017<-.5 & zftblack2017>=-.5 & zftmuslim2017<-.5
replace sortrightf17=1 if zfthisp2017<-.5 & zftgay2017>=-.5 & zftblack2017<-.5 & zftmuslim2017<-.5
replace sortrightf17=1 if zfthisp2017>=-.5 & zftgay2017<-.5 & zftblack2017<-.5 & zftmuslim2017<-.5
replace sortrightf17=1 if zfthisp2017<-.5 & zftgay2017<-.5 & zftblack2017<-.5 & zftmuslim2017<-.5
replace sortrightf17=. if zfthisp2017==.
replace sortrightf17=. if zftgay2017==.
replace sortrightf17=. if zftblack2017==.
replace sortrightf17=. if zftmuslim2017==.

gen sortleftf17=0
replace sortleftf17=1 if zfthisp2017>.5 & zftgay2017>.5 & zftblack2017>.5 & zftmuslim2017<=.5
replace sortleftf17=1 if zfthisp2017>.5 & zftgay2017>.5 & zftblack2017<=.5 & zftmuslim2017>.5
replace sortleftf17=1 if zfthisp2017>.5 & zftgay2017<=.5 & zftblack2017>.5 & zftmuslim2017>.5
replace sortleftf17=1 if zfthisp2017<=.5 & zftgay2017>.5 & zftblack2017>.5 & zftmuslim2017>.5
replace sortleftf17=1 if zfthisp2017>.5 & zftgay2017>.5 & zftblack2017>.5 & zftmuslim2017>.5
replace sortleftf17=. if zfthisp2017==.
replace sortleftf17=. if zftgay2017==.
replace sortleftf17=. if zftblack2017==.
replace sortleftf17=. if zftmuslim2017==.

***2012
gen sortrightf12=0
replace sortrightf12=1 if zfthisp2012<-.5 & zftgay2012<-.5 & zftblack2012<-.5 & zftmuslim2012>=-.5
replace sortrightf12=1 if zfthisp2012<-.5 & zftgay2012<-.5 & zftblack2012>=-.5 & zftmuslim2012<-.5
replace sortrightf12=1 if zfthisp2012<-.5 & zftgay2012>=-.5 & zftblack2012<-.5 & zftmuslim2012<-.5
replace sortrightf12=1 if zfthisp2012>=-.5 & zftgay2012<-.5 & zftblack2012<-.5 & zftmuslim2012<-.5
replace sortrightf12=1 if zfthisp2012<-.5 & zftgay2012<-.5 & zftblack2012<-.5 & zftmuslim2012<-.5
replace sortrightf12=. if zfthisp2012==.
replace sortrightf12=. if zftgay2012==.
replace sortrightf12=. if zftblack2012==.
replace sortrightf12=. if zftmuslim2012==.


gen sortleftf12=0
replace sortleftf12=1 if zfthisp2012>.5 & zftgay2012>.5 & zftblack2012>.5 & zftmuslim2012<=.5
replace sortleftf12=1 if zfthisp2012>.5 & zftgay2012>.5 & zftblack2012<=.5 & zftmuslim2012>.5
replace sortleftf12=1 if zfthisp2012>.5 & zftgay2012<=.5 & zftblack2012>.5 & zftmuslim2012>.5
replace sortleftf12=1 if zfthisp2012<=.5 & zftgay2012>.5 & zftblack2012>.5 & zftmuslim2012>.5
replace sortleftf12=1 if zfthisp2012>.5 & zftgay2012>.5 & zftblack2012>.5 & zftmuslim2012>.5
replace sortleftf12=. if zfthisp2012==.
replace sortleftf12=. if zftgay2012==.
replace sortleftf12=. if zftblack2012==.
replace sortleftf12=. if zftmuslim2012==.

*sorting feeling therms; descriptive stats

svyset [pweight=weight_2017]


svy: mean sortleftf17 if dem2012==1
svy: mean sortleftf12 if dem2012==1

svy: mean sortrightf17 if rep2012==1
svy: mean sortrightf12 if rep2012==1

svy: mean sortleftf17 if white2017==1 & dem2012==1
svy: mean sortleftf12 if white2012==1 & dem2012==1

svy: mean sortrightf17 if white2017==1 & rep2012==1
svy: mean sortrightf12 if white2012==1 & rep2012==1

svy: mean sortleftf17 if black2017==1 & dem2012==1
svy: mean sortleftf12 if black2012==1 & dem2012==1

svy: mean sortrightf17 if black2017==1 & rep2012==1
svy: mean sortrightf12 if black2012==1 & rep2012==1


*logit regression for feeling thermometer sort; Table 1 column 1 and 2


svy: logit sortleftf17 sortleftf12 dem2012 liberal2012 fluid2016 newsint2012 changenewsint1712 internet2012 black2012 hisp2012 asian2012 other2012 chatt2012 male2012 educ2012 age2012  faminc2012 changefaminc1712

svy: logit sortrightf17 sortrightf12 rep2012 conservative2012 fixed2016 newsint2012 changenewsint1712 internet2012  black2012 hisp2012 asian2012 other2012 chatt2012 male2012 educ2012 age2012  faminc2012 changefaminc1712


*margins analysis

*find means for variables to be used in margins analysis
svy: mean newsint2012
svy: mean changenewsint1712
svy: mean internet2012
svy: mean chatt2012
svy: mean educ2012
svy: mean age2012
svy: mean faminc2012
svy: mean changefaminc1712




*leftsort, therms
quietly: svy: logit sortleftf17 i.sortleftf12 i.dem2012 i.liberal2012 i.fluid2016 newsint2012 changenewsint1712 internet2012 i.race2012 chatt2012 i.male2012 educ2012 age2012  faminc2012 changefaminc1712

margins, dydx(dem2012) at(sortleftf12=0)
margins dem2012, at(liberal2012=(0 1) male=(0 1) fluid=(0 1) race2012=1 sortleftf12=0 newsint2012=(.768) changenewsint=(-.002) internet2012=(.572) chatt2012=(.353) educ2012=(3.17) age2012=(47.8) faminc2012=(5.7) changefaminc1712=(.606))

*rightsort, therms
quietly: svy: logit sortrightf17 i.sortrightf12 i.rep2012 i.conservative2012 i.fixed2016 newsint2012 changenewsint1712 internet2012 i.race2012 chatt2012 i.male2012 educ2012 age2012  faminc2012 changefaminc1712

margins, dydx(rep2012) at(sortrightf12=0)
margins rep2012, at(conservative2012=(0 1) male=(0 1) fixed=(0 1) race2012=1 sortrightf12=0 newsint2012=(.768) changenewsint=(-.002) internet2012=(.572) chatt2012=(.353) educ2012=(3.17) age2012=(47.8) faminc2012=(5.7) changefaminc1712=(.606))

margins, dydx(conservative2012) at(sortrightf12=0)
margins rep2012, at(conservative2012=(0 1) male=(0 1) fixed=(0 1) race2012=1 sortrightf12=0 newsint2012=(.768) changenewsint=(-.002) internet2012=(.572) chatt2012=(.353) educ2012=(3.17) age2012=(47.8) faminc2012=(5.7) changefaminc1712=(.606))




*panel analysis on attitude measures, 2012 to 2016

svyset [pweight=weight_2016]

*descriptive stats on change from 2012 to 2016, Figure 3a

svy: mean changeraceatt1612 if dem2012==1
svy: mean changeraceatt1612 if rep2012==1
svy: mean changeraceatt1612 if dem2012==0 & rep2012==0

svy: mean changeimmigration1612 if dem2012==1
svy: mean changeimmigration1612 if rep2012==1
svy: mean changeimmigration1612 if dem2012==0 & rep2012==0

svy: mean changeabort1612 if dem2012==1
svy: mean changeabort1612 if rep2012==1
svy: mean changeabort1612 if dem2012==0 & rep2012==0

svy: mean changetaxbizreg1612 if dem2012==1
svy: mean changetaxbizreg1612 if rep2012==1
svy: mean changetaxbizreg1612 if dem2012==0 & rep2012==0


*generating sortleft and sortright dummies

gen sortleftj16=0
replace sortleftj16=1 if raceatt2016<.5 & taxbizreg2016<.5 & immigration2016<.5 & abort2016>=.5
replace sortleftj16=1 if raceatt2016<.5 & taxbizreg2016<.5 & immigration2016>=.5 & abort2016<.5
replace sortleftj16=1 if raceatt2016<.5 & taxbizreg2016>=.5 & immigration2016<.5 & abort2016<.5
replace sortleftj16=1 if raceatt2016>=.5 & taxbizreg2016<.5 & immigration2016<.5 & abort2016<.5
replace sortleftj16=1 if raceatt2016<.5 & taxbizreg2016<.5 & immigration2016<.5 & abort2016<.5
replace sortleftj16=. if raceatt2016==.
replace sortleftj16=. if taxbizreg2016==.
replace sortleftj16=. if immigration2016==.
replace sortleftj16=. if abort2016==.


gen sortrightj16=0
replace sortrightj16=1 if raceatt2016>.5 & taxbizreg2016>.5 & immigration2016>.5 & abort2016<=.5
replace sortrightj16=1 if raceatt2016>.5 & taxbizreg2016>.5 & immigration2016<=.5 & abort2016>.5
replace sortrightj16=1 if raceatt2016>.5 & taxbizreg2016<=.5 & immigration2016>.5 & abort2016>.5
replace sortrightj16=1 if raceatt2016<=.5 & taxbizreg2016>.5 & immigration2016>.5 & abort2016>.5
replace sortrightj16=1 if raceatt2016>.5 & taxbizreg2016>.5 & immigration2016>.5 & abort2016>.5
replace sortrightj16=. if raceatt2016==.
replace sortrightj16=. if taxbizreg2016==.
replace sortrightj16=. if immigration2016==.
replace sortrightj16=. if abort2016==.


gen sortleftj12=0
replace sortleftj12=1 if raceatt2012<.5 & taxbizreg2012<.5 & immigration2012<.5 & abort2016>=.5
replace sortleftj12=1 if raceatt2012<.5 & taxbizreg2012<.5 & immigration2012>=.5 & abort2016<.5
replace sortleftj12=1 if raceatt2012<.5 & taxbizreg2012>=.5 & immigration2012<.5 & abort2016<.5
replace sortleftj12=1 if raceatt2012>=.5 & taxbizreg2012<.5 & immigration2012<.5 & abort2016<.5
replace sortleftj12=1 if raceatt2012<.5 & taxbizreg2012<.5 & immigration2012<.5 & abort2016<.5
replace sortleftj12=. if raceatt2012==.
replace sortleftj12=. if taxbizreg2012==.
replace sortleftj12=. if immigration2012==.
replace sortleftj12=. if abort2012==.


gen sortrightj12=0
replace sortrightj12=1 if raceatt2012>.5 & taxbizreg2012>.5 & immigration2012>.5 & abort2016<=.5
replace sortrightj12=1 if raceatt2012>.5 & taxbizreg2012>.5 & immigration2012<=.5 & abort2016>.5
replace sortrightj12=1 if raceatt2012>.5 & taxbizreg2012<=.5 & immigration2012>.5 & abort2016>.5
replace sortrightj12=1 if raceatt2012<=.5 & taxbizreg2012>.5 & immigration2012>.5 & abort2016>.5
replace sortrightj12=1 if raceatt2012>.5 & taxbizreg2012>.5 & immigration2012>.5 & abort2016>.5
replace sortrightj12=. if raceatt2012==.
replace sortrightj12=. if taxbizreg2012==.
replace sortrightj12=. if immigration2012==.
replace sortrightj12=. if abort2012==.


*descriptive stats on sortleft and sortright, Figure 3b
svy: mean sortleftj16 if dem2012==1
svy: mean sortrightj16 if rep2012==1
svy: mean sortleftj12 if dem2012==1
svy: mean sortrightj12 if rep2012==1

svy: mean sortleftj16 if white2016==1 & dem2012==1
svy: mean sortrightj16 if white2016==1 & rep2012==1
svy: mean sortleftj12 if white2012==1 & dem2012==1
svy: mean sortrightj12 if white2012==1 & rep2012==1

svy: mean sortleftj16 if black2016==1 & dem2012==1
svy: mean sortrightj16 if black2016==1 & rep2012==1
svy: mean sortleftj12 if black2012==1 & dem2012==1
svy: mean sortrightj12 if black2012==1 & rep2012==1


*logit regression on sortleft/sortright on attitude measures, Table 1, columns 3 and 4
svyset [pweight=weight_2016]


svy: logit sortleftj16 sortleftj12 dem2012 liberal2012 fluid2016 newsint2012 changenewsint1612 internet2012 black2012 hisp2012 asian2012 other2012 chatt2012 male2012 educ2012 age2012  faminc2012 changefaminc1612

svy: logit sortrightj16 sortrightj12 rep2012 conservative2012 fixed2016 newsint2012 changenewsint1612 internet2012 black2012 hisp2012 asian2012 other2012 chatt2012 male2012 educ2012 age2012  faminc2012 changefaminc1612


*margins analysis
*leftsort, attitude measures
svyset [pweight=weight_2016]


*means for variables with 2016 weight for margins analysis
svy: mean newsint2012
svy: mean changenewsint1612
svy: mean internet2012
svy: mean chatt2012
svy: mean educ2012
svy: mean age2012
svy: mean faminc2012
svy: mean changefaminc1612

quietly: svy: logit sortleftj16 i.sortleftj12 i.dem2012 i.liberal2012 i.fluid2016 newsint2012 changenewsint1612 internet2012 i.race2012 chatt2012 i.male2012 educ2012 age2012  faminc2012 changefaminc1612

margins, dydx(dem2012) at(sortleftj12=0)
margins dem2012, at(liberal2012=(0 1) male=(0 1) fluid=(0 1) race2012=1 sortleftj12=0 newsint2012=(.766) changenewsint1612=(.014) internet2012=(.567) chatt2012=(.366) educ2012=(3.17) age2012=(45.9) faminc2012=(5.66) changefaminc1612=(.427))
margins, dydx(liberal2012) at(sortleftj12=0)
margins liberal2012, at(dem2012=(1) male=(0 1) fluid=(0 1) race2012=1 sortleftj12=0 newsint2012=(.766) changenewsint1612=(.014) internet2012=(.567) chatt2012=(.366) educ2012=(3.17) age2012=(45.9) faminc2012=(5.66) changefaminc1612=(.427))


*rightsort, attitude measures
quietly: svy: logit sortrightj16 i.sortrightj12 i.rep2012 i.conservative2012 i.fixed2016 newsint2012 changenewsint1612 internet2012 i.race2012 chatt2012 i.male2012 educ2012 age2012  faminc2012 changefaminc1612

margins, dydx(rep2012) at(sortrightj12=0)
margins rep2012, at(conservative2012=(0 1) male=(0 1) fixed=(0 1) race2012=1 sortrightj12=0 newsint2012=(.766) changenewsint1612=(.014) internet2012=(.567) chatt2012=(.366) educ2012=(3.17) age2012=(45.9) faminc2012=(5.66) changefaminc1612=(.427))
margins, dydx(conservative2012) at(sortrightj12=0)
margins conservative2012, at(rep=(1) male=(0 1) fixed=(0 1) race2012=1 sortrightj12=0 newsint2012=(.766) changenewsint1612=(.014) internet2012=(.567) chatt2012=(.366) educ2012=(3.17) age2012=(45.9) faminc2012=(5.66) changefaminc1612=(.427))






******************
*printing table

svyset [pweight=weight_2017]

quietly: asdoc svy: logit sortleftf17 sortleftf12 dem2012 liberal2012 fluid2016 newsint2012 changenewsint1712 internet2012 black2012 hisp2012 asian2012 other2012 chatt2012 male2012 educ2012 age2012  faminc2012 changefaminc1712, nest replace

quietly: asdoc svy: logit sortrightf17 sortrightf12 rep2012 conservative2012 fixed2016 newsint2012 changenewsint1712 internet2012 black2012 hisp2012 asian2012 other2012 chatt2012 male2012 educ2012 age2012  faminc2012 changefaminc1712, nest

svyset [pweight=weight_2016]

quietly: asdoc svy: logit sortleftj16 sortleftj12 dem2012 liberal2012 fluid2016 newsint2012 changenewsint1612 internet2012 black2012 hisp2012 asian2012 other2012 chatt2012 male2012 educ2012 age2012  faminc2012 changefaminc1612, nest

asdoc svy: logit sortrightj16 sortrightj12 rep2012 conservative2012 fixed2016 newsint2012 changenewsint1612 internet2012 black2012 hisp2012 asian2012 other2012 chatt2012 male2012 educ2012 age2012  faminc2012 changefaminc1612, nest






